<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>OAuth Example</title>
    <script type="text/javascript">
        var auths = null;
        var sweixin = null;
        // 监听plusready事件  
        document.addEventListener("plusready", function() {
            // 扩展API加载完毕，现在可以正常调用扩展API
            plus.oauth.getServices(function(services) {
                auths = services;
                sweixin = shares['weixin'];
            }, function(e) {
                alert("获取分享服务列表失败：" + e.message + " - " + e.code);
            });
        }, false);
        // 发送分享
        function doShare(srv, msg) {
            outLine(JSON.stringify(msg));
            srv.send(msg, function() {
                outLine('分享到"' + srv.description + '"成功！');
            }, function(e) {
                outLine('分享到"' + srv.description + '"失败: ' + JSON.stringify(e));
            });
        }
        // 分享小程序
        function shareMiniProgram() {
            if (!sweixin) {
                plus.nativeUI.alert('当前环境不支持微信分享操作!');
            }
            var msg = {
                type: 'miniProgram',
                title: '分享小程序标题',
                thumbs: ['_www/mp.png']
            };
            msg.content = '分享小程序描述内容。';
            msg.miniProgram = {
                id: 'g_XXXXXXX', // 小程序的原始标识
                webUrl: 'http://www.dcloud.io/'
            };
            // 发送分享
            if (sweixin.authenticated) {
                doShare(sweixin, msg);
            } else {
                sweixin.authorize(function() {
                    doShare(sweixin, msg);
                }, function(e) {
                    console.log('认证授权失败：' + JSON.stringify(e));
                });
            }
        }
    </script>
</head>

<body>
    <button onclick="shareMiniProgram()">分享小程序</button>
</body>

</html>